<?php

namespace App\Http\Controllers\manage;

use App\Model\Clue;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;

class ClueController extends Controller
{
    /**
     * 线索列表
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index() {
        $clue = Clue::all();
        return view('manage.clue.index',['clue'=>$clue,'active1'=>1,'active2'=>1]);
    }

    /**
     * 线索状态管理
     * @return array
     */
    public function clueStatus() {
        $id = Input::get('id');
        $status = Input::get('status');
        if($status == 0) {
            $map = Clue::where('id',$id)->update(['status'=>0]);
            $code = 0;
            $msg = '设置成功！';
        }elseif($status == 1){
            $map = Clue::where('id',$id)->update(['status'=>1]);
            $code = 1;
            $msg = '设置成功！';
        }elseif($status == 2){
            $map = Clue::where('id',$id)->update(['status'=>2]);
            $code = 2;
            $msg = '设置成功！';
        }elseif($status == 3){
            $map = Clue::where('id',$id)->update(['status'=>3]);
            $code = 3;
            $msg = '设置成功！';
        }elseif($status == 4){
            $map = Clue::where('id',$id)->update(['status'=>4]);
            $code = 4;
            $msg = '设置成功！';
        }else {
            $map = null;
            $code = 102;
            $msg = '设置失败！';
        }
        if(!$map){
            return [
                'code'=>101,
                'msg'=>'设置失败！'
            ];
        }
        return [
            'code'=>$code,
            'msg'=>$msg
        ];
    }
}
